<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AngelScript: ref object</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   
   </div>
   
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('doc_addon_handle.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">ref object </div>  </div>
</div>
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scripthandle/</p>
<p>The <code>ref</code> type is a generic container that can hold any handle. It is a value type, but behaves very much like an object handle.</p>
<p>The type is registered with <code>RegisterScriptHandle(asIScriptEngine*)</code>.</p>
<dl class="see"><dt><b>See also:</b></dt><dd><a class="el" href="doc_adv_generic_handle.html">Registering a generic handle type</a></dd></dl>
<h2><a class="anchor" id="doc_addon_handle_1"></a>
Public C++ interface</h2>
<div class="fragment"><pre class="fragment"><span class="keyword">class </span>CScriptHandle 
{
<span class="keyword">public</span>:
  <span class="comment">// Constructors</span>
  CScriptHandle();
  CScriptHandle(<span class="keyword">const</span> CScriptHandle &amp;other);
  CScriptHandle(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> typeId);
  ~CScriptHandle();

  <span class="comment">// Copy the stored reference from another handle object</span>
  CScriptHandle &amp;operator=(<span class="keyword">const</span> CScriptHandle &amp;other);
  CScriptHandle &amp;opAssign(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> typeId);

  <span class="comment">// Compare equalness</span>
  <span class="keywordtype">bool</span> opEquals(<span class="keyword">const</span> CScriptHandle &amp;o) <span class="keyword">const</span>;
  <span class="keywordtype">bool</span> opEquals(<span class="keywordtype">void</span> *ref, <span class="keywordtype">int</span> typeId) <span class="keyword">const</span>;

  <span class="comment">// Dynamic cast to desired handle type</span>
  <span class="keywordtype">void</span> opCast(<span class="keywordtype">void</span> **outRef, <span class="keywordtype">int</span> typeId);
};
</pre></div><h2><a class="anchor" id="doc_addon_handle_3"></a>
Example usage</h2>
<p>In the scripts it can be used as follows:</p>
<pre>
  ref@ unknown;</pre><pre>  // Store a handle in the ref variable
  object obj;
  @unknown = @obj;</pre><pre>  // Compare equalness
  if( unknown != null ) 
  {
    // Dynamically cast the handle to wanted type
    object @obj2 = cast&lt;object&gt;(unknown);
    if( obj2 != null )
    {
      ...
    }
  }
</pre> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Sun Jan 29 2012 15:41:03 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
